#include "businesslogic.hpp"

using lms::bussinesslogic::OrderServices;


OrderServices::OrderServices()
{
    orders = new LinkedList< Order >();
    actualOrder = null;
}

LinkedList< Order >* OrderServices::getOrders()
{
    return orders;
}

Order* OrderServices::getActualOrder()
{
    return actualOrder;
}

void OrderServices::setCustomerOrder(Customer* customer)
{
    if( actualOrder == null )
        actualOrder = new Order();
    actualOrder->setCustomer( customer );
}

void OrderServices::addBook(Book* bookSelected,int amount )
{
    if( actualOrder == null )
        actualOrder =  new Order();
    OrderDetail* orderDetail = new OrderDetail( amount,bookSelected );
    actualOrder->addOrderDetail( orderDetail );
}

void OrderServices::removeBook(int index)
{
    if( actualOrder != null )
        actualOrder->removeOrderDetail( index );
}
void OrderServices::checkout()
{
    if( actualOrder != null && orders !=null )
    {
        orders->add( actualOrder );
    actualOrder = null;
    }
}

void OrderServices::cancel()
{
    delete actualOrder;
    actualOrder = null;
}
